<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>考勤记录</title>
	<link rel="stylesheet" href="../css/common2.css">
	<link rel="stylesheet" href="../css/urlty.css">
	<link rel="stylesheet" href="/scriptZIP/vue-select.min.css">
	<style>
		.state {
			color: white;
			border-radius: 3px;
			font-size: 14px;
			font-weight: bold;
			padding: 4px;
			background-color: #4BAF4F;
		}

		.conduct {
			background-color: #F8B551;
		}

		.end {
			background-color: #E64919;
		}

		.class-end {
			background-color: #9F9F9F;
		}

		#vue-root {
			padding-top: 20px;
		}
		.search_img1 {
			position: absolute;
			
		}
		
  .search1 {
    width: 15vw;
    max-width: 140px;
    height: 35px;
    padding-left: 10px;
    font-size: 14px;
    color: #686868;
    /* position: absolute; */
    right: 100px;
    border: 1px solid;
    display: inline-block;
  }

	</style>
</head>

<body>
	<div id="vue-root">
		<div class="href_head" style="margin-top: 60px;">
			<div class="refresh action-buttons" onclick="location.reload()">刷新</div>
			<!-- <a href="attendance_count.html">
				<div class="delete">考勤统计</div>
			</a>
			<div class="delete long-background-img" @click="show_download=true">下载历史考勤记录</div> -->
			<input placeholder="请输入学员姓名" class="search1" v-model="search.name" style="height: 33px;">
			<!-- <input class="other" placeholder="请输入卡号" v-model="search.cardNo" @keyup.enter="getData0"
				style="position: absolute; right: 420px; margin-top: 5px;" /> -->
			<!-- <div class="chooses">
				<select class="classes search" v-model="search.classesId"
					style="position: absolute; right: 260px; margin-top: -80px;">
					<option :value="undefined">请选择班级</option>
					<option v-for="classes in classess" :key="classes.id" :value="classes.id" v-text="classes.name">
					</option>
				</select>
			</div> -->
				<select class="search1" v-model="search.schoolId">
					<option :value="undefined">请选择校区</option>
					<option v-for="school in schools" :key="school.id" :value="school.id" v-text="school.name">
					</option>
				</select>

				<select class="search1" v-model="search.status">
					<option :value="undefined">请选择进出状态</option>
					<option :value="0">签到</option>
					<option :value="1">签退</option>
					<!-- <option :value="2">进校</option>
					<option :value="3">离校</option>
					<option :value="4">迟到</option>
					<option :value="5">早退</option> -->
				</select>
			
				<select class="search1" v-model="search.courseId">
							<option :value="undefined">请选择课程</option>
							<option v-for="course in courses" :key="course.id" :value="course.id" v-text="course.name">
							</option>
						</select>
						<v-select  v-model="search.teacherId" :options="teachers" label="name" :reduce="teacher => teacher.id"
							 placeholder="请选择教师" :filterable="true" :clearable="true" style="width: 150px; display: inline-block;" ></v-select>
		
		<input placeholder="开始时间" class="search1" v-model="search.startTime" id="startTime">
		<input placeholder="结束时间" class="search1" v-model="search.endTime" id="endTime">

		<img src="../image/search.png" height="35" width="35" class="search_img" @click="getData0">
		<div class="table">
			<table class="table_top">
				<thead>
					<tr>
						<th class="one">
							<input type="checkbox" class="check-box" v-model="all">序号
						</th>
                        <th>校区</th>
						<th>学生姓名</th>
						<th>课程</th>
						<th>上课老师</th>
						<th>班级</th>
						<th>刷卡时间</th>
						<th>拍照</th>
						<th>进出状态</th>
						<th v-if="able.del">删除</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(attendance,index) in list" :key="attendance.id">
						<td class="one">
							<input type="checkbox" class="check-box" v-model="attendance.checked">
							<span v-text="index+1"></span>
						</td>
                        <td v-text="attendance.schoolName"></td>
						<td v-text="attendance.studentName"></td>
						<td v-text="attendance.courseName"></td>
						<td v-text="attendance.teacherName"></td>
						<td v-text="attendance.classesName"></td>
						<td v-text="attendance.time"></td>
						<td class="two photo">
							<img v-for="pic in pics(attendance.pic)" :src="getImg(pic)" alt="" @click="bigImg(pic)">
						</td>
						<td v-text="['签到','签退'][attendance.status]"></td>
						<td v-if="able.del">
							<div>
								<div class="delete-icon option-icon" @click="del([attendance.id])">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'" />
								</div>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		</div>
		<br>
		<div class="delete" @click="batchDelete" v-if="able.del">批量删除</div>
		<div class="delete long-background-img" v-if="able.export" @click="exports">批量导出</div>

		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>
		<div style="float: right;margin-bottom: 20px;">
			总共{{total}}条记录
			<select class="ui-select init" style="margin-top: 14px;" v-model="pageSize">
				<option :value="10">每页10条</option>
				<option :value="30">每页30条</option>
				<option :value="100">每页100条</option>
			</select>
		</div>
		<div v-if="bigimg" @click="bigimg=false">
			<div class="img_layer"></div>
			<img :src="big_src" class="big_Img">
		</div>
	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>
	<script src="/scriptZIP/dayjs.min.js"></script>
	<script src="/scriptZIP/vue-select.min.js"></script>
	<script src="/lib/laydate/laydate.js"></script>

	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>
		Vue.component('v-select', VueSelect.VueSelect);
		var schoolId = top_params().id;
		var app = new Vue(merge({
			data: {
				classess: [],
				devices: [],
				search: {
					// only: false,
				},
				urls: {
					del: '/pc/attendance/del'
				},
				show: false,
				date: null,
				show_download: false,
				download_times: [],
                schools:[],
				courses:[],
				teachers:[]
			},
			created: function () {
				if (!schoolId) {
					alert('未知学校');
					throw '未知学校';
				}
				this.schoolId = schoolId;
				axios.get('/pc/classes/all/' + schoolId).then(function (res) {
					this.classess = res.data;
				}.bind(this));
                axios.get('/pc/school/all/' + schoolId).then(function (res) {
					this.schools = res.data;
				}.bind(this));
				axios.get('/pc/course/all/' + schoolId).then(function (res) {
					this.courses = res.data;
				}.bind(this));
				axios.get('/pc/teacher/allAgent/' + schoolId).then(function (res) {
					this.teachers = res.data;
				}.bind(this));
				this.urls.list = '/api/attendanceRecord/list?agentId=' + schoolId;
				this.getData();
				axios.get('/pc/device/all/' + schoolId).then(function (res) {
					this.devices = res.data;
				}.bind(this));
				abled('sellManage', this);
				// 获取当前月份
				for (var i = 0; i <= 5; i++) {
					this.download_times.push(dayjs().subtract(i, 'month').format('YYYY-MM'))
				}
			},
			methods: {
				getImg: function (pic) {
					if (!pic) return null;
					return  pic;
				},
				bigImg: function (pic) {
					this.big_src = this.getImg(pic);
					this.bigimg = true;
				},
				exports: function () {
					var q = Qs.stringify(this.search);
					if (q) q = '&' + q;
					location.href = '/api/attendanceRecord/export?agentId=' + this.schoolId + q;
				},
				submit: function () {
					if (!this.date) {
						alert('请选择时间点');
						return;
					}
					this.show = false;
					axios.delete('/pc/attendance/' + this.schoolId, {
						params: {
							date: this.date
						}
					}).then(function (res) {
						this.getData();
						alert('删除成功');
						this.date = null;
					}.bind(this));
				},
				pics: function (pics) {
					if (!pics) return [];
					return pics.split(',');
				},
				download: function (month, teacher) {
					axios.get('/pc/attendance/exist/' + schoolId + '/' + teacher + '/' + month).then(function (res) {
						if (!res.data.exist) return alert('暂无数据');
						open('/static/' + schoolId + '/' + (teacher ? 't' : 's') + '_' + month + '.xlsx');
					});
				}
			},
			watch: {
				show: function (newValue, oldValue) {
					if (newValue) {
						this.$nextTick(function () {
							laydate.render({
								elem: '#layday',
								type: 'datetime',
								done: function (value, date, endDate) {
									this.date = value;
								}.bind(this)
							});
						}.bind(this));
					}
				},
				'search.only': function (newValue, oldValue) {
					if (newValue) this.search.classesId = null;
				},
				'search.classesId': function (newValue, oldValue) {
					if (newValue && this.search.only) this.search.only = null;
				}
			}
		}));

		laydate.render({
			elem: '#startTime',
			type: 'datetime',
			done: function (value, date, endDate) {
				app.search.startTime = value;
			}
		});

		laydate.render({
			elem: '#endTime',
			type: 'datetime',
			done: function (value, date, endDate) {
				app.search.endTime = value;
			}
		});
	</script>

</body>

</html>